<?php
/**
 * Created by PhpStorm.
 * User: yangfan
 * Date: 2020/1/15
 * Time: 2:08 PM
 */

namespace App\Utils;

use Illuminate\Support\Facades\Redis;

class TradeNoGeneratorUtil
{
    public const TRADE_NO_IDENTIFY = 'TRADE_NO_IDENTIFY:';

    /**
     * @return string
     */
    public static function get(): string
    {
        $timestamp = time();
        $key = self::TRADE_NO_IDENTIFY . $timestamp;

        $nu = Redis::incr($key);
        Redis::expire($key, 5);

        return (string)Date('YmdHis', $timestamp) . $timestamp . sprintf('%06s', $nu);
    }
}
